﻿@{
    ViewBag.Title = "Common Command";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<ol class="breadcrumb">
    <li><a href="/Home/Home">Home</a></li>
    <li><a href="/Common/CommonIntoduction"> Sanelib Common</a></li>
    <li class="active">Service-Day Description</li>
</ol>
<div id="introduction">
    <h1 class="text-left">DayDescriptionService</h1>
    <p><strong>IDayDescriptionService Interface</strong><br/>In IDayDescriptionService Interface that defines two methods First SetHolidays type has one perameter array of Holiday Method which have return void.second GetDays type Method  have two parameter startdate and enddate type of datetime which have return array of DayDescription type.
    <pre><code>public interface IDayDescriptionService<br/>{<br/>void SetHolidays(Holiday[] holidays);<br/>DayDescription[] GetDays(DateTime startDate, DateTime endDate);<br/>}</code></pre>
    Here,DayDescriptionService is extend by IDayDescriptionService from<strong>Common ClassLibrary </strong> in <strong>Service Project </strong> Show in Below. 
    <pre><code>public class DayDescriptionService : IDayDescriptionService<br/>{<br />private static readonly object Lock = new object();<br />private static readonly List&lt;daydescription&gt; DaysTable = new List&lt;daydescription&gt;(500);<br />private static Holiday[] _holidays = new Holiday[0];<br />public void SetHolidays(Holiday[] holidays)<br/>{<br/>lock (Lock)<br/>{<br/>_holidays = holidays;<br/>}<br/>}<br/>}<br/></code></pre>
    In,SetHolidays method that set Holidays.
    <br/>In DayDescriptionServive has contains DayDescription[] GetDays() Method show in Below.
    <pre><code>public DayDescription[] GetDays(DateTime startDate, DateTime endDate)<br />{<br/>lock (Lock)<br />{<br/> if (DaysTable.Count == 0)<br/>{<br/> DaysTable.AddRange(GetDayDescriptions(startDate, endDate));<br/>}<br/>else<br/>{<br/>var firstCollectionDate = DaysTable.First().GetDate();<br/>var lastCollectionDate = DaysTable.Last().GetDate();<br/>if (firstCollectionDate > startDate)<br/>{<br/>DaysTable.InsertRange(0, GetDayDescriptions(startDate, firstCollectionDate.AddDays(-1)));<br/>}<br/>if (lastCollectionDate < endDate)<br/>{<br/>DaysTable.InsertRange(DaysTable.Count - 1, GetDayDescriptions(lastCollectionDate.AddDays(1), endDate));<br/>}<br/>}<br />}<br/>return DaysTable.Where(d => d.GetDate() >= startDate && d.GetDate() <= endDate).ToArray();<br/>}</code></pre>
    <p>this Method getdays Discription between startdate and enddate and this is return to DaysTable type of List .</p>
</div>

      